#pragma once
#include <D3D11.h>
#include <xnamath.h>
#include <string>

#define KEYDOWN(name, key)( name[key] & 0x80 )
#define BUTTONDOWN(device, key)( device.rgbButtons[key] & 0x80 )

static std::string WcharToString(WCHAR *str)
{
  std::string result;
  int i = 0;
  while(str[i] != 0)
    result += str[i++];

  return result;
}

struct VertexPos
{  
  XMFLOAT3 pos;
  XMFLOAT2 tex0;

  VertexPos()
  {
    pos = XMFLOAT3();    
    tex0 = XMFLOAT2();
  }
};

struct Vertex
{
  XMFLOAT3 pos;
  XMFLOAT3 norm;
  XMFLOAT2 tex0;

  Vertex()
  {
    pos = XMFLOAT3(0,0,0);
    norm = XMFLOAT3(0,0,0);
    tex0 = XMFLOAT2(0,0);
  }

  bool operator==(const Vertex vertex)
  {    
    if(this->pos.x == vertex.pos.x && this->pos.y == vertex.pos.y && this->pos.z == vertex.pos.z &&
      this->norm.x == vertex.norm.x && this->norm.y == vertex.norm.y && this->norm.z == vertex.norm.z &&
      this->tex0.x == vertex.tex0.x && this->tex0.y == vertex.tex0.y)
      return true;

    return false;
  }
};

struct Material
{
  XMFLOAT3 Ambient;
  XMFLOAT3 Diffuse;
  XMFLOAT3 Specular;

  int Shininess;
  float Alpha;

  bool IsSpecular;

  std::string TextureName;
  ID3D11Texture2D* Texture;
  //d3d11h D3DXHANDLE hTechnique;
};


struct MeshDesc
{
  Vertex* Vertices;
  WORD* Indices;
  unsigned int NumVertices, NumIndices, NumMaterials;
  Material* Materials;
};

struct RenderDesc
{
  ID3D11Buffer* VertexBuffer;
  ID3D11Buffer* IndexBuffer;
  unsigned int TotalVertices, TotalIndices, TotalMaterials;  
  Material* Materials;
};

struct AABBDesc
{
  AABBDesc() : Extents(XMFLOAT3(0,0,0)), Center(XMFLOAT3(0,0,0)) {}
  XMFLOAT3 Extents,Center;
};


struct TextureDesc
{
  ID3D11ShaderResourceView* ColorMap;
  ID3D11SamplerState* ColorMapSampler;
};


namespace Chess
{
  enum FieldStatusEnum { NONE = 0, CANREACH, SELECTED};
  enum ColorEnum { WHITE = 0, BLACK };
  enum FigureTypeEnum { BISHOP = 0, KING, KNIGHT, PAWN, QUEEN, ROOK, FIELD, BOARD };
};

